package my209;

public class SuanFa209HuaDongChuangKou {

        public int minSubArrayLen(int target, int[] nums) {
            int length = nums.length;
            if (length == 0) {
                return 0;
            }
            int right = 0;
            int left = 0;
            int n = Integer.MAX_VALUE;
            int sum = 0;
            while (right < length) {
                sum += nums[right];
                while (sum >= target) {
                    n = Math.min(n, right - left + 1);
                    sum -= nums[left];
                    left++;
                }
                right++; // 更新右边界位置
            }
            return n == Integer.MAX_VALUE ? 0 : n; // 处理没有符合条件的情况
        }

    public static void main(String[] args) {
        SuanFa209HuaDongChuangKou suanFa209HuaDongChuangKou = new SuanFa209HuaDongChuangKou();
        int[] num = {3,2,4,1,5};
        int n = suanFa209HuaDongChuangKou.minSubArrayLen(7, num);
        System.out.println(n);
    }
}
